#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>

void *thread_main(void *arg);

int main(int argc,char *argv[])
{
    pthread_t t_id;
    int thread_param=5;
    void *thr_ret;

    pthread_create(&t_id, NULL, thread_main, &thread_param);
    pthread_join(t_id, &thr_ret);

    printf("线程返回消息: %s\n", (char *)thr_ret);
    free(thr_ret);
    return 0;
}

void *thread_main(void *arg)
{
    int cnt = *((int *)arg);
    char *msg = (char *)malloc(sizeof(char) * 30);
    strcpy(msg, "这里是线程\n");
    for(int i = 0;i < cnt;++i) {
        sleep(1);
        printf("执行线程 %d 次\n", i + 1);
    }
    return (void *)msg;
}